//
//  UIImage+DP.m
//  圆形裁剪图片
//
//  Created by DP on 16/7/6.
//  Copyright © 2016年 dp. All rights reserved.
//

#import "UIImage+DP.h"

@implementation UIImage (DP)
+ (UIImage *)clipImageToCircl:(UIImage *)sourceImage {
    
    //1.开启位图上下文
    UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, 0);
    //2.设置裁剪区域
    //创建路径
    UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, sourceImage.size.width, sourceImage.size.width)];
    //设置路径为裁剪区域
    [path addClip];
    //4.绘制图片到上下文
    [sourceImage drawAtPoint:CGPointZero];
    //5.生成新图片
    UIImage *imageN = UIGraphicsGetImageFromCurrentImageContext();
    //6.关闭上下文
    UIGraphicsEndImageContext();
    return imageN;
}
@end
